//
//  YeeShopCarTableViewCell.m
//  YeeShopProject
//
//  Created by CoderYee on 2017/3/8.
//  Copyright © 2017年 CoderYee. All rights reserved.
//

#import "YeeShopCarTableViewCell.h"
@interface YeeShopCarTableViewCell ()
{
    UIView  *_deleteView;//模拟删除视图
    UIView  *_infoView;//模拟删除视图
    UIView  *_touchView;//数量按钮
    UIButton    *_addButton;
    UIButton    *_releaseButton;
}
@end
@implementation YeeShopCarTableViewCell

-(void)addOwnView
{
    [self addfaultView];
    [self addinfoView];
    //[self addDeleteView];
    
}
-(void)bindViewModel
{
    
    
}
-(void)addfaultView
{
    _selectedButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [_selectedButton setImage:[[UIImage imageNamed:@"icon_zhifenda_xuanzhong"] imageWithTintColor:kNavBarThemeColor] forState:UIControlStateNormal];
    [self.contentView addSubview:_selectedButton];
    [_selectedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).with.offset(5.0f);
        make.height.width.mas_equalTo(17);
    }];
    
    _coverImageView=[[UIImageView alloc] init];
    _coverImageView.contentMode=UIViewContentModeScaleAspectFill;
    _coverImageView.clipsToBounds=YES;
    [_coverImageView sd_setImageWithURL:[NSURL URLWithString:@"http://upload-images.jianshu.io/upload_images/2741392-05c026a0c4fff732.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"] placeholderImage:defaultPImage options:SDWebImageTransformAnimatedImage];
    [self.contentView addSubview:_coverImageView];
    [_coverImageView mas_makeConstraints:^(MASConstraintMaker *make)
     {   make.centerY.equalTo(self.contentView);
         make.left.equalTo(_selectedButton.mas_right).offset(10);
         make.height.width.mas_equalTo(85);
    }];
}
-(void)addinfoView
{
    _infoView=[[UIView alloc] init];
    [self.contentView addSubview:_infoView];
    [_infoView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(_coverImageView.mas_right).offset(5);
         make.right.top.bottom.equalTo(self.contentView);
     }];
    
    _titleLable=[[UILabel alloc] init];
    _titleLable.font=[UIFont Y_systemFontOfSize:13];
    _titleLable.numberOfLines=0;
    _titleLable.textColor=kBlackColor;
    _titleLable.text=@"袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子袜子";
    [_infoView addSubview:_titleLable];
    
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(_infoView).with.offset(10);
         make.right.equalTo(_infoView).with.offset(-10);
         make.top.equalTo(_coverImageView.mas_top);
    }];
    
    _desLable=[[UILabel alloc] init];
    _desLable.font=[UIFont Y_systemFontOfSize:11];
    _desLable.textColor=kGrayColor;
    _desLable.numberOfLines=0;
    _desLable.text=@"颜色:黑色 尺寸：180";
    [_infoView addSubview:_desLable];
    [_desLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(_infoView).with.offset(10);
         make.right.equalTo(_infoView).with.offset(-10);
         make.top.equalTo(_titleLable.mas_bottom).offset(5);
     }];
    _priceLable=[[UILabel alloc] init];
    _priceLable.font=[UIFont Y_systemFontOfSize:11];
    _priceLable.textColor=kGrayColor;
    _priceLable.text=@"$254";
    [_infoView addSubview:_priceLable];
    [_priceLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(_infoView).with.offset(10);
         make.height.mas_equalTo(21);
         make.top.equalTo(_desLable.mas_bottom).offset(5);
     }];
    
    _oldpriceLable=[[UILabel alloc] init];
    _oldpriceLable.font=[UIFont Y_systemFontOfSize:11];
    _oldpriceLable.textColor=kGrayColor;
    NSString *textStr = [NSString stringWithFormat:@"%@元", @"23233"];
    //中划线
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
    // 赋值
    _oldpriceLable.attributedText = attribtStr;
    [_infoView addSubview:_oldpriceLable];
    [_oldpriceLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(_priceLable.mas_right).with.offset(10);
         make.height.mas_equalTo(21);
         make.top.equalTo(_desLable.mas_bottom).offset(5);
     }];
    
    
//    _touchView=[[UIView alloc] init];
//    _touchView.layer.cornerRadius=5.0;
//    _touchView.layer.masksToBounds=YES;
//    _touchView.layer.borderWidth=0.2;
//    //[_touchView setBackgroundColor:xBackgroundColor];
//    _touchView.layer.borderColor=kGrayColor.CGColor;
//    [_infoView addSubview:_touchView];
//    [_touchView mas_makeConstraints:^(MASConstraintMaker *make)
//     {
//         make.left.equalTo(_oldpriceLable.mas_right).offset(20.0);
//         make.height.mas_equalTo(30);
//         make.right.equalTo(_infoView).with.offset(-25);
//         make.centerY.equalTo(_oldpriceLable.mas_centerY);
//     }];
//    
//    
//    _releaseButton=[UIButton buttonWithType:UIButtonTypeCustom];
//    [_releaseButton setImage:[UIImage imageNamed:@"jianhao"] forState:UIControlStateNormal];
//    _releaseButton.imageEdgeInsets=UIEdgeInsetsMake(0, -15, 0, 0);
//    _releaseButton.tag=101;
//    [_touchView addSubview:_releaseButton];
//    [_releaseButton mas_makeConstraints:^(MASConstraintMaker *make)
//     {
//         make.left.equalTo(_touchView);
//         make.centerY.equalTo(_touchView);
//         make.height.mas_equalTo(35);
//         make.width.mas_equalTo(40);
//     }];
//    
//    _addButton=[UIButton buttonWithType:UIButtonTypeCustom];
//    _addButton.imageEdgeInsets=UIEdgeInsetsMake(0, 0, 0, -10);
//
//    [_addButton setImage:[UIImage imageNamed:@"jia"] forState:UIControlStateNormal];
//    _addButton.tag=100;
//    [_touchView addSubview:_addButton];
//    [_addButton mas_makeConstraints:^(MASConstraintMaker *make)
//     {
//         make.right.equalTo(_touchView);
//         make.centerY.equalTo(_touchView);
//         make.height.mas_equalTo(35);
//         make.width.mas_equalTo(40);
//     }];
//
//    _countLable=[[UILabel alloc] init];
//    _countLable.textColor=kGrayColor;
//    _countLable.text=@"90000";
//    _countLable.font=[UIFont Y_systemFontOfSize:12];
//    [_touchView addSubview:_countLable];
//    
//    [_countLable mas_makeConstraints:^(MASConstraintMaker *make)
//     {
//         make.center.equalTo(_touchView);
//    }];
    
    
    CGSize size = CGSizeMake(20, 20);
    UIImage *background = [self yy_imageWithSize:size drawBlock:^(CGContextRef context) {
        UIColor *c0 = [UIColor colorWithRed:0.054 green:0.879 blue:0.000 alpha:1.000];
        UIColor *c1 = [UIColor colorWithRed:0.869 green:1.000 blue:0.030 alpha:1.000];
        [c0 setFill];
        CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));
        [c1 setStroke];
        CGContextSetLineWidth(context, 2);
        for (int i = 0; i < size.width * 2; i+= 4) {
            CGContextMoveToPoint(context, i, -2);
            CGContextAddLineToPoint(context, i - size.height, size.height + 2);
        }
        CGContextStrokePath(context);
    }];
    
   // one.yy_color = [UIColor colorWithPatternImage:background];
    
}
- (UIImage *)yy_imageWithSize:(CGSize)size drawBlock:(void (^)(CGContextRef context))drawBlock {
    if (!drawBlock) return nil;
    UIGraphicsBeginImageContextWithOptions(size, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    if (!context) return nil;
    drawBlock(context);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
-(void)addDeleteView
{
    _deleteView=[[UIView alloc] init];
    [_deleteView setBackgroundColor:kWhiteColor];
    [self.contentView addSubview:_deleteView];
    [_deleteView mas_makeConstraints:^(MASConstraintMaker *make)
     {   make.left.equalTo(_coverImageView.mas_right).offset(5);
         make.right.top.bottom.equalTo(self.contentView);
     }];
    
    UIView *view=[[UIView alloc] init];
    [view setBackgroundColor:kNavBarThemeColor];
    [_deleteView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.top.equalTo(_deleteView);
        //make.centerY.equalTo(_deleteView);
        make.width.mas_equalTo(40);
       // make.height.mas_equalTo(80);
    }];
    
    UIButton *deleteButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [deleteButton setTitle:@"删除" forState:UIControlStateNormal];
    [deleteButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [view addSubview:deleteButton];
    [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(view);
        make.height.width.mas_equalTo(40);
    }];
    
    
}
@end
